﻿$(function(){//延迟加载
	var dpname=$('#dpname').val();
	var departmentId=$('#departmentId').val();
	$('#addnewuserdetail').propertygrid({
		width:'330px',
		data:{"total":8,"rows":[    
		    	                  {'name':'所属部门','value':dpname,'group':'ID Settings','editor':{
		    	                	  'editable':false
		    	                  }},
		    	                  {"name":"邮箱","group":"ID Settings","editor":{    
		    	                      "type":"validatebox",    
		    	                      "options":{    
		    	                      "required":true   
		    	                     }    
		    	                  }},
		    	                  {"name":"姓名","group":"ID Settings","editor":{    
		    	                      "type":"validatebox",    
		    	                      "options":{    
		    	                      "required":true   
		    	                     }    
		    	                  }},
		    	                  {"name":"电话","group":"ID Settings","editor":{    
		    	                      "type":"validatebox",    
		    	                      "options":{    
		    	                      "required":true   
		    	                     }    
		    	                  }},
		    	                  {"name":"固定电话","group":"ID Settings","editor":{    
		    	                      "type":"validatebox",    
		    	                      "options":{    
		    	                      "required":true   
		    	                     }    
		    	                  }},
		    	                  {"name":"生日","group":"ID Settings","editor":{    
		    	                      "type":'datetimebox',    
		    	                     }},  
		    	                  {"name":"ifleader","group":"ID Settings","editor":{
		    	                	  type:'checkbox',
		    	                	  options:{
		    	                		required:true,
		    	                		on:'1',
		    	                		off:'0'
		    	                	}
		    	                  }},
		    	                  {"name":"职位","group":"ID Settings","editor":{
		    	                	  type:'combobox',
		    	                	  options:{
		  								valueField:'roleId',
		  								textField:'rolename',
		  								method:'get',
		  								url:'getrolesofdepartment?departmentId='+departmentId,
		  								required:true
		  							}
		    	                  }},
		    	                  {"name":"员工工号","group":"ID Settings","editor":{    
		    	                      "type":"validatebox",    
		    	                      "options":{    
		    	                      "required":true   
		    	                     }    
		    	                  }}
		    	              ]},
		columns:[[
		         {'field':'name','title':'新人员','width':'120px'},
		         {'field':'value','title':'','width':'170px'}		          		          
		          ]],
		//showHeader:false		    	              
	});
	
	$('#addusercompl').linkbutton({
		plain:true,
		iconCls:'icon-ok',
		onClick:function(){
			var email=$('#addnewuserdetail').propertygrid('getRows')[1].value;
			if(email==undefined)email='';
			var username=$('#addnewuserdetail').propertygrid('getRows')[2].value;
			if(username==undefined)username='';
			var dpname=$('#addnewuserdetail').propertygrid('getRows')[0].value;
			
			var tel=$('#addnewuserdetail').propertygrid('getRows')[3].value;
			var loctel=$('#addnewuserdetail').propertygrid('getRows')[4].value;
			var birthday=$('#addnewuserdetail').propertygrid('getRows')[5].value;
			if(birthday==undefined)birthday='';
			var ifleader=$('#addnewuserdetail').propertygrid('getRows')[6].value;
			if(ifleader==undefined)ifleader='0';
			var roleId=$('#addnewuserdetail').propertygrid('getRows')[7].value;
			var usercode=$('#addnewuserdetail').propertygrid('getRows')[8].value;
//			alert(birthday);
			$.ajax({
				url:'adduser',
				type:'POST',
				data:{
					departmentId:departmentId,
					email:email,
					username:username,
					tel:tel,
					dpname:dpname,
					loctel:loctel,
					birthday:birthday,
					ifleader:ifleader,
					roleId:roleId,
					usercode:usercode
					//rolename:rolename
				},				
				success:function(data){
					alert(data.msg);
				}
			});
		}
	});
	
})